#coding:utf-8

sina_title = '//h1[@id="artibodyTitle"]'
sina_content = '//div[@id="artibody"]'

netease_title = '//h1[@id="h1title"]'
netease_content = '//div[@id="endText"]'

tencent_title = '//div[@class="hd"]/h1'
tencent_content = '//div[@id="Cnt-Main-Article-QQ"]'

sohu_title = '//h1[@itemprop="headline"]'
sohu_content = '//div[@id="contentText"]/div[@itemprop="articleBody"]'

# S = dict()
# S['news.sina.com.cn'] = 'sina'
# S['news.163.com'] = '163'
# S['news.qq.com'] = 'qq'
# S['news.sohu.com'] = 'sohu'

# E = dict()
# E['news.sina.com.cn'] = 'GBK'
# E['news.163.com'] = 'GBK'
# E['news.qq.com'] = 'GBK'
# E['news.sohu.com'] = 'GBK'

X = dict()
X['sina'] = dict()
X['sina']['t'] = sina_title
X['sina']['c'] = sina_content
X['163'] = dict()
X['163']['t'] = netease_title
X['163']['c'] = netease_content
X['qq'] = dict()
X['qq']['t'] = tencent_title
X['qq']['c'] = tencent_content
X['sohu'] = dict()
X['sohu']['t'] = sohu_title
X['sohu']['c'] = sohu_content

def extract_site(uri):
	line = uri[len('http://'):]
	s = line.split('/')
	s = s[0]
	return s


class RssSource(object):

	def __init__(self):
		self.X = X
		# self.site_to_name = S
		# self.site_to_info = E

	def get_code(self,uri):
		site = extract_site(uri)
		if site not in self.site_to_info.keys():
			return None
		return self.site_to_info[site]


	def get_xpath(self,uri):
		site = extract_site(uri)
		site = site.split('.')[1]
		if site not in self.X.keys():
			return None

		title = self.X[site]['t']
		content = self.X[site]['c']
		m = dict()
		m['title'] = title
		m['content'] = content
		return m

